﻿/// <summary>
/// 时间：2020.4.26
/// 作用：职责链模式
/// 更新：
/// </summary>
namespace CommonLib.Pattern
{
	/// <summary>
	/// 职责链的节点
	/// </summary>
	public abstract class IChainNode
	{
		public int ChainLevel { get; protected set; }

		protected IChainNode Next_ChainNode { get; set; }
	
		public void SetNextNode(IChainNode _next)
		{
			this.Next_ChainNode = _next;
		}	

		public void Deal(object _entity)
		{
			//处理_entity的行为
			if (!TryDeal(_entity))
			{
				//超出能力范围转到下一节点处理
				this.Next_ChainNode?.Deal(_entity);
			}
		}

		/// <summary>
		/// 具体的处理操作
		/// </summary>
		/// <param name="o"></param>
		/// <returns></returns>
		abstract protected bool TryDeal(object o);
	}
}